<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Survey extends CI_Controller {
	
	/** 
	 *	Academic survey Page
	 *	成本收益问卷调研页面
	 *
	 */

	public function __construct() {
		parent::__construct();
		$this->load->model('options_model');
		$this->load->library('form_validation');
	}
	
	public function index() {

		/* 后端验证 */
		$this->form_validation->set_rules('prov', '1.1.1 省/直辖市/自治区', 'required');
		$this->form_validation->set_rules('city', '1.1.2 市/区/自治州', 'required');
		$this->form_validation->set_rules('dist', '1.1.3 县/市/区', 'required');
		$this->form_validation->set_rules('address', '1.2 详细地址', 'required');
		$this->form_validation->set_rules('type_of_cultivation', '1.3 栽培类型', 'required');
		$this->form_validation->set_rules('function_of_protection', '1.4 设施功能', 'callback__validate_cultivation_type');
		$this->form_validation->set_rules('structure_of_protection', '1.5 设施结构', 'callback__validate_cultivation_type');
		$this->form_validation->set_rules('is_sightseeing', '1.6 是否观光', 'required');
		$this->form_validation->set_rules('total_area', '1.7 总面积', 'required');
		$this->form_validation->set_rules('variety_name[]', '1.8.1 品种名称', 'required');
		$this->form_validation->set_rules('variety_area[]', '1.8.2 品种面积', 'required');
		$this->form_validation->set_rules('variety_usage_select[]', '1.8.3 品种用途选项', 'required');
		$this->form_validation->set_rules('variety_usage[]', '1.8.3 品种用途', 'required');

		$this->form_validation->set_rules('type_of_growers', '2.1 种植者类型', 'required');
		$this->form_validation->set_rules('is_primary_income', '2.2 主要收入', 'required');
		$this->form_validation->set_rules('is_in_cooperative', '2.3 加入合作社', 'required');
		$this->form_validation->set_rules('average_age', '2.4 平均年龄', 'required');
		$this->form_validation->set_rules('education', '2.5 学历', 'required');
		$this->form_validation->set_rules('creer_length', '2.6 种植时间', 'required');
		$this->form_validation->set_rules('is_trained', '2.7 接受培训', 'required');

		$this->form_validation->set_rules('built_in', '3.1 建园时间', 'required');
		$this->form_validation->set_rules('vineyard_lifetime', '3.2 使用年限', 'required');
		$this->form_validation->set_rules('is_land_owner', '3.3 是否自家土地', 'required');
		$this->form_validation->set_rules('cost_land_rent', '3.4.1 显性土地成本', '');
		$this->form_validation->set_rules('local_land_price', '3.4.2 当地租金', '');
		$this->form_validation->set_rules('cost_built_materials', '3.5 建园物质', 'required');
		$this->form_validation->set_rules('cost_built_labor', '3.6 建园人工', 'required');
		$this->form_validation->set_rules('cost_renovation', '3.7 维护费', '');

		$this->form_validation->set_rules('force_validate', '强制验证失败', 'required');

		if ($this->form_validation->run() == FALSE) { // 验证未通过
			$this->load->view('survey/intergrated');
			$this->load->view('templates/validation');
			$this->output->enable_profiler(TRUE);	// 显示调试信息
		}

		else { // 验证通过
			$this->load->view('templates/debug');
		}
	}

	public function _validate_cultivation_type($str) { // 验证栽培模式逻辑
		if($this->input->post('type_of_cultivation') == '设施栽培' && ($str == '' || $str == 'default')) {
			$this->form_validation->set_message('_validate_type', "is_required");
			return FALSE;
		}
		return TRUE;
	}

	public function create() {
		$this->form_validation->set_rules('total_area', '种植面积', 'required');

		if($this->form_validation->run() == FALSE) {
			$this->index();
		}
		else {
			$this->survey_model->set_survey_main();
		}
	}
}

/* End of file survey.php */
/* Location: ./application/controllers/survey.php */